#include "inThread.h"

InThread::InThread()
{
    pTimer = NULL ;
}

InThread & InThread::getInstance ()
{
    static InThread inThread ;
    return inThread ;
}

void InThread::operator()(boost::asio::io_service& io) 
{
    initPolling(io) ;
}

void InThread::initPolling (boost::asio::io_service& io)
{
    pTimer = new boost::asio::deadline_timer(io, boost::posix_time::seconds(1)) ;
    pTimer->async_wait(boost::bind(&InThread::rxMsg, this)) ;
}
    
void InThread::rxMsg () 
{
    std::cout<< "InThread: Receive a msg" << std::endl ;
    
    pTimer->expires_at(pTimer->expires_at() + boost::posix_time::seconds(1));
    pTimer->async_wait(boost::bind(&InThread::rxMsg, this));
}
